import {ActionsTree, defineStore, GettersTree, Store} from 'pinia';
import { store } from '/@/store';

interface AppState {
    pageLoading: boolean
}

/**
 * setup 里面使用
 */
export const appStore = defineStore({
    id: 'app',
    state: (): AppState => ({
        pageLoading: false
    }),
    getters: {
        getPageLoading(): boolean {
            return this.pageLoading;
        },
    },
    actions: {
        setPageLoading(loading: boolean): void {
            this.pageLoading = loading;
        },
    }
})

/**
 * 外部使用，在没有 setup 时  使用
 */
export function useAppStoreWithOut(): Store<string, AppState,  GettersTree<AppState>, ActionsTree> {
    return appStore(store);
}